// var noticeArray = [];
// //[id,title]
// noticeArray.push(["100", "部门周例会会议通知1"]);
// noticeArray.push(["200", "部门周例会会议通知2"]);
// noticeArray.push(["300", "部门周例会会议通知3"]);
// noticeArray.push(["400", "部门周例会会议通知4"]);
// noticeArray.push(["500", "部门周例会会议通知5"]);ticeArray.length;
// 公告数量

if(noticeArray.length == 0)
	noticeArray.push(["-1", "今天没有公告"]);

/*******************************************************************************
 * 公告栏 start
 */
var marqueeInterval = new Array();
var marqueeId = 0;
var marqueeDelay = 100000;
// 停顿时间 (ms)
var marqueeHeight = 30;
// 公告栏高度
var marqueeWidth = 400;
// 公告栏宽度
var dir = 'left';
// 滚动方向up/left up为向上滚动，left为向左滚动
var separatorBefore = "<div style='width:400px;text-align:center;line-height:20px;height:20px'><font color='black' style='font-weight:bolder'>*";
var separatorAfter = "</font></div>"
if(dir == "left")
	leafscroll();
else
	upscroll();

/**
 * 向左滚动
 */
function leafscroll() {
	var str = "";
	if(noticeArray[0][0] == "-1")
		return;
	for(var i = 0; i < noticeArray.length; i++) {
		str += separatorBefore;
		var item = '<a onclick="viewNotice(' + String(noticeArray[i][0]) + ')" style="cursor:pointer;"><' + +noticeArray[i][2] + ">" + noticeArray[i][1] + '</a>';
		str += item;
		str += separatorAfter;
	}
	noticeDiv = '<div id="marqueeBox" style="overflow:hidden;height:' + marqueeHeight + 'px;width:' + marqueeWidth + 'px;margin:5px;border:2px solid #1d953f;font-size:12px;color:red;"><div style="float:left;width: 800%;"><div id="notice1" style="float:left;">' + str + '</div><div id="notice2" style="float:left;">' + str + '</div></div></div>';

	var noticeBar = document.getElementById("noticeBar");
	noticeBar.innerHTML = noticeDiv

	marqueeInterval[3] = window.setInterval(LeftStartFn, 10);

	function LeftStartFn() {
		if(dir == "up") {
			noticeBar.innerHTML = "";
			window.clearInterval(marqueeInterval[3]);
			upscroll();
			return;
		}
		var marqueeBox = document.getElementById("marqueeBox");
		var notice1 = document.getElementById("notice1");
		var notice2 = document.getElementById("notice2");

		if(notice2.offsetWidth - marqueeBox.scrollLeft <= 0)
			marqueeBox.scrollLeft -= notice1.offsetWidth
		else {
			marqueeBox.scrollLeft++;
		}
		marqueeBox.onmouseover = function() {
			window.clearInterval(marqueeInterval[3])
		};
		marqueeBox.onmouseout = function() {
			marqueeInterval[3] = window.setInterval(LeftStartFn, 10)
		};
	}

}

function upscroll() {
	var str = "<a onclick='javascript:new UICtrl.ShowNoNotice(" + noticeArray[0][0] + ");' style='cursor:pointer;'>" + noticeArray[0][1] + "</a>";
	if(noticeArray[0][0] == "-1") {
		str = noticeArray[0][1];
	} else {
		marqueeId++;
	}
	noticeDiv = '<div id="marqueeBox" style="overflow:hidden;height:' + marqueeHeight + 'px;width:' + marqueeWidth + 'px;margin:5px;border:2px solid #1d953f;font-size:12px;color:red;"><div>' + str + '</div></div>';
	var noticeBar = document.getElementById("noticeBar");
	noticeBar.innerHTML = noticeDiv;

	marqueeInterval[0] = window.setInterval(upStartFn, 3000);

	function upStartFn() {

		if(dir == "left") {
			noticeBar.innerHTML = "";
			window.clearInterval(marqueeInterval[0]);
			window.clearInterval(marqueeInterval[1]);
			leafscroll();
			return;
		}
		var marqueeBox = document.getElementById("marqueeBox");

		if(noticeArray[marqueeId])
			var str = "<a onclick='javascript:alert(" + noticeArray[marqueeId][0] + ");' style='cursor:pointer;'>" + noticeArray[marqueeId][1] + "</a>";

		if(noticeArray[0][0] == "-1")
			str = noticeArray[0][1];
		marqueeId++;
		if(marqueeId >= noticeArray.length)
			marqueeId = 0;

		if(marqueeBox.childNodes.length == 1) {
			var nextLine = document.createElement('DIV');
			nextLine.innerHTML = str;
			nextLine.style.width = marqueeWidth;
			marqueeBox.appendChild(nextLine);
		} else {
			marqueeBox.childNodes[0].innerHTML = str;
			marqueeBox.appendChild(marqueeBox.childNodes[0]);
			marqueeBox.scrollTop = 0;
		}
		marqueeBox.onmouseover = function() {
			window.clearInterval(marqueeInterval[0])
		}
		marqueeBox.onmouseout = function() {
			marqueeInterval[0] = window.setInterval(upStartFn, 3000);
		}
		if(marqueeInterval[1])
			window.clearInterval(marqueeInterval[1]);
		marqueeInterval[1] = window.setInterval(scrollFn, 1000);
	}

	function scrollFn() {
		var marqueeBox = document.getElementById("marqueeBox");
		marqueeBox.scrollTop++;
		if(marqueeBox.scrollTop % marqueeHeight == (marqueeHeight - 1)) {
			window.clearInterval(marqueeInterval[1]);
		}
	}

}

function left() {
	dir = 'left';
}

function up() {
	dir = 'up';
}

function viewNotice(noticeId) {
	var url = viewNoticeLink + "?notice.id=" + noticeId;
	window.open(url, 'noticeWin', 'width=300,height=300,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');
}